package com.material.controller;

import com.github.pagehelper.PageInfo;
import com.material.common.annotation.LoginUser;
import com.material.common.base.CommonController;
import com.material.common.core.domain.entity.SysUser;
import com.material.common.entity.ResultResponse;
import com.material.common.utils.DateUtils;
import com.material.common.utils.bean.BeanUtil;
import com.material.factory.domain.FactoryReceivingPlan;
import com.material.factory.params.FactoryReceivingPlanParams;
import com.material.factory.service.IFactoryReceivingPlanService;
import com.material.factory.vo.FactoryReceivingPlanDataVo;
import com.material.request.BaseRequest;
import com.material.supplier.domain.SupplierInfo;
import com.material.supplier.service.ISupplierInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author ganxinge
 */
@Api(tags = "8.工厂收货计划")
@RestController
@RequestMapping("/plan")
public class FactoryReceivingPlanController extends CommonController {

    @Autowired
    private IFactoryReceivingPlanService factoryReceivingPlanService;
    @Autowired
    private ISupplierInfoService supplierInfoService;

    @ApiOperation("计划列表")
    @GetMapping("/list")
    public ResultResponse list(@ApiIgnore @LoginUser SysUser sysUser, BaseRequest params){
        Long factoryId = 0L;
        String userType = sysUser.getUserType();
        if (SysUser.USER_TYPE_3.equals(userType)){
            Long supplierId = sysUser.getBizId();
            SupplierInfo supplierInfo = supplierInfoService.selectSupplierInfoById(supplierId);
            factoryId = supplierInfo.getFactoryId();
        }
        if(SysUser.USER_TYPE_1.equals(userType) || SysUser.USER_TYPE_2.equals(userType)){
            factoryId = sysUser.getBizId();
        }
        FactoryReceivingPlanParams factoryReceivingPlanParams = BeanUtil.copyProperties(params, FactoryReceivingPlanParams.class);
        factoryReceivingPlanParams.setFactoryId(factoryId);
        PageInfo<FactoryReceivingPlanDataVo> pageInfo = factoryReceivingPlanService.selectFactoryReceivingPlanDateList(factoryReceivingPlanParams);
        return ResultResponse.success(pageInfo);
    }

    @ApiOperation("今日计划列表")
    @GetMapping("/todayList")
    public ResultResponse todayList(@ApiIgnore @LoginUser SysUser sysUser, BaseRequest params){
        Long factoryId = sysUser.getBizId();
        FactoryReceivingPlanParams factoryReceivingPlanParams = BeanUtil.copyProperties(params, FactoryReceivingPlanParams.class);
        factoryReceivingPlanParams.setFactoryId(factoryId);
        factoryReceivingPlanParams.setDate(DateUtils.getDate());
        PageInfo<FactoryReceivingPlanDataVo> pageInfo = factoryReceivingPlanService.selectFactoryReceivingPlanDateList(factoryReceivingPlanParams);
        return ResultResponse.success(pageInfo);
    }
}
